package bk;

//MenuDemo.java
import java.awt.*; 
import java.awt.event.*;
/* save and retrieve memos using a menu. (by W. Savitch)*/
public class MenuDemo extends Frame implements ActionListener {
  /**
	 * 
	 */
	private static final long serialVersionUID = 1L;
public static final int WIDTH = 500;
  public static final int HEIGHT = 300;
  public static final int X = 100;
  public static final int Y = 30;
  private TextArea theText;
  private String memo1 = "No Memo 1.";
  private String memo2 = "No Memo 2.";
  public MenuDemo() {
      setTitle("Memo Saver");
      setSize(WIDTH, HEIGHT);
      setLocation(X, Y);
      setBackground(Color.blue);
      addWindowListener(new WindowDestroyer());

	Menu comm = new Menu("System Commands");
      MenuItem m; 
      m = new MenuItem("Clear"); 
      m.addActionListener(this);
      comm.add(m); 
      m = new MenuItem("Exit"); 
      m.addActionListener(this);
      comm.add(m);

	Menu saveMemo = new Menu("Save Memos");
      m = new MenuItem("Save Memo 1"); 
      m.addActionListener(this);
      saveMemo.add(m); 

      m = new MenuItem("Save Memo 2"); 
      m.addActionListener(this);
      saveMemo.add(m); 
      Menu getMemo = new Menu("Get Memos");
      m = new MenuItem("Get Memo 1"); 
      m.addActionListener(this);
      getMemo.add(m); 
      m = new MenuItem("Get Memo 2"); 
      m.addActionListener(this);
      getMemo.add(m); 
    
      MenuBar mBar = new MenuBar();
      mBar.add(comm);
      mBar.add(saveMemo);
      mBar.add(getMemo);
      setMenuBar(mBar);
      Panel textPanel = new Panel();
      textPanel.setBackground(Color.blue);
      theText = new TextArea(10, 50);
      theText.setBackground(Color.white);
      textPanel.add(theText);
      setLayout(new FlowLayout());
      add(textPanel);
  }
  public void actionPerformed(ActionEvent e) {
      String actionCommand = e.getActionCommand();
      if (actionCommand.equals("Save Memo 1"))
          memo1 = theText.getText();
      else if (actionCommand.equals("Save Memo 2"))
          memo2 = theText.getText();
      else if (actionCommand.equals("Clear"))
          theText.setText("");
      else if (actionCommand.equals("Get Memo 1"))
          theText.setText(memo1);
      else if (actionCommand.equals("Get Memo 2"))
          theText.setText(memo2);

  else if (actionCommand.equals("Exit"))
      System.exit(0);
  else 
      theText.setText("Error in memo interface.");
      
 repaint();
} 

public static void main(String[] args) {
  MenuDemo menuGUI = new MenuDemo();
  menuGUI.setVisible(true);
}
}
